package o;

import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
import androidx.annotation.Nullable;
import com.huawei.appgallery.assistantdock.buoydock.bean.GetGameBuoyEntryInfoResp;
import com.huawei.appgallery.assistantdock.buoydock.uikit.window.WindowFrameLayout;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.gamebox.plugin.gameservice.bean.GameInfo;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;
import com.huawei.updatesdk.service.otaupdate.UpdateStatusCode.DialogButton;
import java.util.List;

import o.bgq.e;

public class bhm extends fai implements o.bgq.ResultCallback, AccountBussinessListener, OnClickListener {
    private static BroadcastReceiver ॱˋ = new SafeBroadcastReceiver() {
        public void onReceiveMsg(Context context, Intent intent) {
            String action = intent.getAction();
            if ("android.intent.action.LOCALE_CHANGED".equals(action)) {
                fam.ॱ().ॱ(context);
                cfw.ˋ();
                Logger.ˎ("MainWindow", "broadcastReceiver locale changed, finish");
            } else if ("android.intent.action.SCREEN_OFF".equals(action)) {
                fam.ॱ().ॱ(context);
                Logger.ˎ("MainWindow", "broadcastReceiver screen off, finish");
            } else {
                Logger.ˎ("MainWindow", "broadcastReceiver action: " + action);
            }
        }
    };
    private bgw ʻ = null;
    private Handler ʻॱ = new Handler();
    private Context ʼ;
    private bha ʽ;
    private ImageView ˊ;
    private LinearLayout ˊॱ;
    private bgx ˋ;
    private int ˋॱ = 200;
    private WindowFrameLayout ˎ;
    private ImageView ˏ;
    private LinearLayout ˏॱ;
    private int ͺ = 100;
    private FrameLayout ॱ;
    private boolean ॱˊ = false;
    private GameInfo ॱॱ;
    private bhe ᐝ = null;

    class c implements Runnable {
        private ccp ˋ;
        final /* synthetic */ bhm ॱ;

        public c(bhm o_bhm, ccp o_ccp) {
            this.ॱ = o_bhm;
            this.ˋ = o_ccp;
        }

        public void run() {
            int i = this.ˋ.ˎ;
            if (102 == i) {
                this.ॱ.ˋ(true);
            } else if (DialogButton.CONFIRM == i) {
                if (this.ॱ.ᐝ != null) {
                    this.ॱ.ᐝ.ˎ(-1000);
                }
            } else if (103 == i) {
                fam.ॱ().ॱ(this.ॱ.ʼ);
                ezs.ˏ().ˊ();
            }
            Logger.ˎ("MainWindow", "onAccountBusinessResult, accountResult = " + this.ˋ.toString());
        }
    }

    public bhm(Context context) {
        this.ʼ = bgh.ˋ(context);
    }

    public void ˋ(@Nullable Bundle bundle) {
        super.ˋ(bundle);
        bgi.ˋ().ˏ("GS0010001_" + UserSession.getInstance().getUserId());
        ʼॱ();
        Logger.ˎ("MainWindow", "onCreate");
    }

    public View ˏ() {
        if (this.ʼ == null) {
            Logger.e("MainWindow", "onCreateView, context == null");
            return null;
        }
        this.ˎ = (WindowFrameLayout) LayoutInflater.from(this.ʼ).inflate(beo$j.ॱᐝ, null);
        this.ˊॱ = (LinearLayout) this.ˎ.findViewById(beo$e.ˋᐝ);
        this.ˏॱ = (LinearLayout) this.ˎ.findViewById(beo$e.ˏॱ);
        if (ˋˊ()) {
            ॱॱ();
        }
        ॱ();
        return this.ˎ;
    }

    private void ॱॱ() {
        this.ॱ = (FrameLayout) this.ˎ.findViewById(beo$e.ˏˏ);
        this.ॱ.setVisibility(0);
        this.ˊ = (ImageView) this.ˎ.findViewById(beo$e.ˎͺ);
        this.ˏ = (ImageView) this.ˎ.findViewById(beo$e.ˊʽ);
        ॱˎ();
        this.ॱ.setOnClickListener(this);
    }

    private void ॱˎ() {
        if (this.ॱ == null || this.ˏ == null || this.ˊ == null) {
            Logger.ˎ("MainWindow", "not refreshGuidView, dockGuideView == null");
            return;
        }
        if (ॱˊ() == dex.d.ˋ) {
            this.ˏ.setVisibility(8);
            this.ˊ.setVisibility(0);
            this.ˊ.setImageResource(beo$d.ˋ);
        } else {
            this.ˊ.setVisibility(8);
            this.ˏ.setVisibility(0);
            if (ᐝॱ() == a.ˋ) {
                this.ˏ.setImageResource(beo$d.ˎ);
            } else {
                this.ˏ.setImageResource(beo$d.ˏ);
            }
        }
        LayoutParams layoutParams = (LayoutParams) this.ॱ.getLayoutParams();
        if (ᐝॱ() == a.ˋ) {
            layoutParams.gravity = 8388627;
        } else {
            layoutParams.gravity = 8388629;
        }
    }

    protected void ॱ() {
        if (ॱˊ() == dex.d.ˋ) {
            ॱᐝ();
        } else {
            ॱˋ();
        }
    }

    private void ॱᐝ() {
        if (!ʽॱ()) {
            if (this.ॱॱ != null) {
                cfw.ˎ(bfn.ˋ(this.ॱॱ), new IServerCallBack(this) {
                    final /* synthetic */ bhm ˏ;

                    {
                        this.ˏ = r1;
                    }

                    public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
                    }

                    public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
                        if (responseBean.getResponseCode() != 0 || !(responseBean instanceof GetGameBuoyEntryInfoResp)) {
                            Logger.e("MainWindow", "onCompleted, responseCode = " + responseBean.getResponseCode());
                        } else if (responseBean.getRtnCode_() != 0 || this.ˏ.ॱॱ == null) {
                            Logger.e("MainWindow", "onCompleted, rtnCode = " + responseBean.getRtnCode_() + ", gameInfo = " + this.ˏ.ॱॱ);
                        } else {
                            ezs.ˏ().ˏ(this.ˏ.ॱॱ, (GetGameBuoyEntryInfoResp) responseBean);
                            if (this.ˏ.ʻ != null) {
                                this.ˏ.ʻ.ˏ();
                                Logger.ˎ("MainWindow", "refresh dock data");
                            }
                        }
                    }
                });
            } else {
                Logger.e("MainWindow", "load entryInfo fail, gameInfo == null");
            }
        }
        if (this.ᐝ != null) {
            try {
                ᐝ().ॱ(this.ᐝ);
                this.ᐝ = null;
            } catch (Exception e) {
                Logger.ˋ("MainWindow", "remove loading Segment failed");
            }
        }
        this.ʻ = new bgw();
        this.ʻ.ˊ(this.ʼ);
        ᐝ().ˋ(beo$e.ˏॱ, this.ʻ, null);
        this.ˊॱ.setVisibility(8);
    }

    private void ॱˋ() {
        if (doo.ˊ(this.ʼ)) {
            this.ॱˊ = false;
            ˈ();
            return;
        }
        this.ॱˊ = true;
        ʾ();
    }

    private void ˈ() {
        if (ʽॱ()) {
            ˊ();
        } else {
            ˋ(true);
        }
    }

    private void ʾ() {
        Logger.ˎ("MainWindow", "addOfflineSegment");
        if (this.ʼ == null) {
            Logger.e("MainWindow", "addOfflineSegment, context == null");
            return;
        }
        if (this.ᐝ != null) {
            ᐝ().ॱ(this.ᐝ);
            this.ᐝ = null;
        }
        this.ˊॱ.setVisibility(0);
        ᐝ().ˋ(beo$e.ꜟ, new bgx(), null);
        ᐝ().ˋ(beo$e.ˉॱ, bhb.ˏ(this.ʼ), null);
        this.ॱˊ = true;
    }

    protected void ˊ() {
        if (this.ʼ == null) {
            Logger.e("MainWindow", "addSegments, context == null");
            return;
        }
        if (this.ᐝ != null) {
            ᐝ().ॱ(this.ᐝ);
            this.ᐝ = null;
        }
        this.ˊॱ.setVisibility(0);
        if (this.ˋ == null) {
            this.ˋ = new bgx();
            ᐝ().ˋ(beo$e.ꜟ, this.ˋ, null);
        }
        if (this.ʽ == null) {
            this.ʽ = bha.ˋ(this.ʼ, null);
            this.ʽ.ˊ(this.ॱॱ);
            this.ʽ.ˊ(ᐝ());
            ᐝ().ˋ(beo$e.ˉॱ, this.ʽ, null);
        }
    }

    private void ʼॱ() {
        try {
            eoj.ˋ().ˎ("MainWindow", this);
            IntentFilter intentFilter = new IntentFilter();
            intentFilter.addAction("android.intent.action.LOCALE_CHANGED");
            intentFilter.addAction("android.intent.action.SCREEN_OFF");
            this.ʼ.registerReceiver(ॱˋ, intentFilter);
        } catch (Throwable e) {
            Logger.ˋ("MainWindow", "registerBroadCast, e: ", e);
        }
    }

    private void ʿ() {
        try {
            this.ʼ.unregisterReceiver(ॱˋ);
        } catch (Throwable e) {
            Logger.ˋ("MainWindow", "unregisterBroadCast, e: ", e);
        }
    }

    public void B_() {
        super.B_();
        fam.ॱ().ˊ(this.ʼ, this);
        Logger.ˎ("MainWindow", "onResume isOffline:" + this.ॱˊ);
        if (this.ॱˊ && doo.ˊ(this.ʼ)) {
            ॱ();
        }
    }

    public void D_() {
        super.D_();
        eoj.ˋ().ˊ("MainWindow");
        bgn.ˎ().ॱ();
        ezs.ˏ().ˊ();
        ʿ();
        Logger.ˎ("MainWindow", "onDestroy");
    }

    private boolean ʽॱ() {
        fae ˏ = fam.ॱ().ˏ();
        if (ˏ != null) {
            this.ॱॱ = ˏ.getGameInfo();
            if (this.ॱॱ == null) {
                Logger.e("MainWindow", "hasEntryInfo, gameInfo == null");
                return false;
            } else if (ezs.ˏ().ˋ(this.ॱॱ) != null) {
                return true;
            } else {
                Logger.e("MainWindow", "hasEntryInfo, buoyEntryInfo == null");
                return false;
            }
        }
        Logger.e("MainWindow", "hasEntryInfo, buoyBridge == null");
        return false;
    }

    private boolean ˋˊ() {
        fae ˏ = fam.ॱ().ˏ();
        if (ˏ != null) {
            bfm requestParams = ˏ.getRequestParams();
            if (requestParams != null) {
                return requestParams.ˏ();
            }
        }
        return false;
    }

    private void ˋ(boolean z) {
        this.ˊॱ.setVisibility(8);
        if (ॱˊ() == dex.d.ˎ) {
            this.ᐝ = new bhe();
            this.ᐝ.ˊ(this.ʼ);
            this.ᐝ.ˋ(this);
            ᐝ().ˋ(beo$e.ˏॱ, this.ᐝ, null);
            if (this.ˋ == null && z) {
                this.ᐝ.ˏॱ();
            }
        }
    }

    public void ˊ(bgq o_bgq, List<cvs> list) {
        if (this.ॱॱ != null) {
            list.add(bfn.ˋ(this.ॱॱ));
            return;
        }
        if (this.ᐝ != null) {
            this.ᐝ.ˎ(-1001);
        }
        Logger.e("MainWindow", "onPrepareRequestParams, gameInfo == null");
    }

    public boolean ˊ(bgq o_bgq, e eVar) {
        ResponseBean responseBean = eVar.mResp;
        if (this.ᐝ != null) {
            this.ᐝ.ˊ(responseBean.getResponseCode(), responseBean.getRtnCode_());
        }
        if (responseBean.getResponseCode() == 0 && (responseBean instanceof GetGameBuoyEntryInfoResp)) {
            GetGameBuoyEntryInfoResp getGameBuoyEntryInfoResp = (GetGameBuoyEntryInfoResp) responseBean;
            if (getGameBuoyEntryInfoResp.getRtnCode_() != 0 || this.ॱॱ == null) {
                Logger.e("MainWindow", "onCompleted, rtnCode = " + getGameBuoyEntryInfoResp.getRtnCode_() + ", gameInfo = " + this.ॱॱ);
            } else {
                ezs.ˏ().ˏ(this.ॱॱ, getGameBuoyEntryInfoResp);
                ˊ();
            }
        } else {
            Logger.e("MainWindow", "onCompleted, responseCode = " + responseBean.getResponseCode());
        }
        return false;
    }

    public View ˊ(int i) {
        if (this.ˎ == null) {
            return null;
        }
        return this.ˎ.findViewById(i);
    }

    public void onAccountBusinessResult(ccp o_ccp) {
        this.ʻॱ.post(new c(this, o_ccp));
    }

    public void onClick(View view) {
        if (this.ॱ.getId() == view.getId()) {
            String str;
            Logger.ˎ("MainWindow", "need to switch dock");
            if (ॱˊ() == dex.d.ˋ) {
                str = "DOCK";
                fam.ॱ().ˏ(this.ʼ, this);
            } else {
                str = "CONTENT";
                ˊᐝ();
            }
            beq.ˋ(str, "SWITCH");
        }
    }

    private void ˊˋ() {
        LinearLayout linearLayout = (LinearLayout) this.ˏॱ.findViewById(beo$e.ʽᐝ);
        if (linearLayout != null) {
            int ˊ;
            linearLayout.animate().alpha(0.0f).setDuration((long) this.ͺ);
            if (this.ʼ.getResources().getConfiguration().orientation == 1) {
                ˊ = (int) (((float) dfc.ˊ(this.ʼ)) * 0.8f);
            } else {
                ˊ = dfc.ˊ(this.ʼ) / 2;
            }
            ˊ(ˊ, dfc.ˎ(this.ʼ) - dfc.ˏ(this.ʼ, 48), new AnimatorListener(this) {
                final /* synthetic */ bhm ˎ;

                {
                    this.ˎ = r1;
                }

                public void onAnimationStart(Animator animator) {
                }

                public void onAnimationEnd(Animator animator) {
                    this.ˎ.ˏॱ.getLayoutParams().width = -1;
                    this.ˎ.ˏॱ.getLayoutParams().height = -1;
                    this.ˎ.ॱˎ();
                    this.ˎ.ॱ();
                }

                public void onAnimationCancel(Animator animator) {
                }

                public void onAnimationRepeat(Animator animator) {
                }
            });
        }
    }

    private void ˊᐝ() {
        if (this.ˊॱ != null) {
            this.ˊॱ.animate().alpha(0.0f).setDuration((long) this.ͺ).withEndAction(new Runnable(this) {
                final /* synthetic */ bhm ˋ;

                {
                    this.ˋ = r1;
                }

                public void run() {
                    this.ˋ.ˊॱ.setAlpha(1.0f);
                }
            });
        }
        if (ᐝॱ() == a.ˋ) {
            fam.ॱ().ˏ(this.ʼ, this);
            ॱˎ();
            ॱ();
            return;
        }
        final int ˏ = dfc.ˏ(this.ʼ, 88);
        final AnimatorListener anonymousClass5 = new AnimatorListener(this) {
            final /* synthetic */ bhm ˋ;

            {
                this.ˋ = r1;
            }

            public void onAnimationStart(Animator animator) {
            }

            public void onAnimationEnd(Animator animator) {
                this.ˋ.ˏॱ.getLayoutParams().width = -1;
                this.ˋ.ˏॱ.getLayoutParams().height = -1;
                fam.ॱ().ˏ(this.ˋ.ʼ, this.ˋ);
                LinearLayout linearLayout = (LinearLayout) this.ˋ.ˏॱ.findViewById(beo$e.ʽᐝ);
                if (linearLayout != null) {
                    linearLayout.setAlpha(1.0f);
                }
            }

            public void onAnimationCancel(Animator animator) {
            }

            public void onAnimationRepeat(Animator animator) {
            }
        };
        ॱᐝ();
        final LinearLayout linearLayout = (LinearLayout) this.ˏॱ.findViewById(beo$e.ʽᐝ);
        if (linearLayout != null) {
            linearLayout.setAlpha(0.0f);
            linearLayout.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener(this) {
                final /* synthetic */ bhm ॱ;

                public void onGlobalLayout() {
                    this.ॱ.ˊ(ˏ, linearLayout.getMeasuredHeight(), anonymousClass5);
                    linearLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                }
            });
        }
    }

    private void ˊ(int i, int i2, AnimatorListener animatorListener) {
        if (this.ˏॱ == null) {
            Logger.e("MainWindow", "startBuoyContainerAnim fail, buoyContainer == null");
            return;
        }
        int measuredWidth = this.ˏॱ.getMeasuredWidth();
        Logger.ˎ("MainWindow", "startBuoyContainerAnim,from " + measuredWidth + "," + this.ˏॱ.getMeasuredHeight() + " to " + i + "," + i2);
        ValueAnimator ofObject = ValueAnimator.ofObject(new bgk(), new Object[]{new o.bgk.c((float) measuredWidth, (float) r1), new o.bgk.c((float) i, (float) i2)});
        ofObject.setDuration((long) this.ˋॱ);
        ofObject.addUpdateListener(new AnimatorUpdateListener(this) {
            final /* synthetic */ bhm ˋ;

            {
                this.ˋ = r1;
            }

            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                o.bgk.c cVar = (o.bgk.c) valueAnimator.getAnimatedValue();
                this.ˋ.ˏॱ.getLayoutParams().width = (int) cVar.ˎ();
                this.ˋ.ˏॱ.getLayoutParams().height = (int) cVar.ˊ();
                this.ˋ.ˏॱ.setLayoutParams(this.ˋ.ˏॱ.getLayoutParams());
                Logger.ˎ("onAnimationUpdate", cVar.ˎ() + " , " + cVar.ˊ());
            }
        });
        ofObject.setInterpolator(new fpn());
        ofObject.addListener(animatorListener);
        ofObject.start();
    }

    public void E_() {
        if (ॱˊ() == dex.d.ˎ) {
            ˊˋ();
        }
        ॱˎ();
        B_();
    }

    public void ˋ() {
        super.ˋ();
        ॱˎ();
    }
}
